<?php @session_start(); ?>

<?php

include "Connect.php";

?>
  <?php // dump_page("06pie.php"); ?>

<?php
$_SESSION['mm'] = "";

$_SESSION['xx'] = "";

$_SESSION['xxp'] = "";

$_SESSION['mande'] = "";

//$mel = $_GET['mel'];
$food = @$_POST['food'];
$snacks = @$_POST['snacks'];
$services = @$_POST['services'];
$drinks = @$_POST['drinks'];
$delete = @$_POST['delete'];
$enterRecord = @$_POST['enterRecord'];

$select = @$_POST['select'];
$rN = @mysql_real_escape_string($_POST['recordName']);
$recordName = ucfirst($rN);
$recordPrice = @mysql_real_escape_string($_POST['recordPrice']);

//$conF = "<meta http-equiv=\"refresh\" content=\"0;URL=retData.php\">";

/*if(!preg_match('/^[a-zA-Z0-9]+$/', $recordName) || !preg_match('/^[a-zA-Z0-9]+$/', $recordPrice)){

     echo "Input contains Invalid characters!!"; 
}
// If our email or PayPal addresses are invalid
if(!preg_match("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $email))
{
     echo "The email or PayPal address you entered is invalid."; // Tell the user
}
*/
//htmlentities(




if(@$_GET['id'] == "mel"){
showFood();
}

if(@$_GET['id']=="cann" and $_SESSION['hG']=="food" ) {
showFood();
}
if(@$_GET['id']=="cann" and $_SESSION['hG']=="drinks" ) {
showDrinks();
}
if(@$_GET['id']=="cann" and $_SESSION['hG']=="snacks" ) {
showSnacks();
}
if(@$_GET['id']=="cann" and $_SESSION['hG']=="services" ) {
showServices();
}


/* if (isset($_GET['page']) and $_SESSION['G'] == "food"){
 $page = $_GET['page'];

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

@$pageFor = "food";
$max_results = 4;

$from = (($page * $max_results) - $max_results);
 
$getData = mysql_query("SELECT * FROM food LIMIT $from, $max_results") or die("Failed to Query the Food table");
$_SESSION['hG'] = $Clicked = "food";
$stuff = "Foods";
$G = "Food";

$_SESSION['G'] = "food";

//echo "Value=". $_SESSION['G'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, Food table Empty";
header("location:dataColl.php?poll=$msg");
//header("location: dataColl.php?poll=$msg");
//include "dataColl.php";
}else{
//colorRow();
$msg =  "Some data found";
//header("location: dataColl.php?poll=$msg");
include "dataColl.php";

} 
   }*/


if($food){

showFood();

 }
else if($drinks){
showDrinks();

}else if($snacks){
showSnacks();

}
else if($services){
showServices();
 }
 
if(isset($delete)){

$checkbox=@$_POST['checkbox'];
if($checkbox == null){

$_SESSION['xx'] = "Please select atleast an item to delete!!";

switch ($_SESSION['hG']) {
case "food":
showFood();
$_SESSION['xx'] = "";
break;
case "drinks":
showDrinks();
break;
case "snacks":
showSnacks();
break;
case "services":
showServices();
break;

}

 
}else{
if($_SESSION['hG']=="food"){
$getD = mysql_query("SELECT * FROM food");
for($i=0;$i<mysql_num_rows($getD);$i++){
$del_id = @$checkbox[$i];
$sql = "DELETE FROM food WHERE ID ='$del_id'";
$result = mysql_query($sql);
}

if($result){/*

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM food LIMIT $from, $max_results") or die(mysql_error());

$stuff = "Foods";
$G = $_SESSION['hG'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, food table Empty";
header("location:dataColl.php?poll=$msg");

}else{

include "dataColl.php";
 }
   */
 

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM food LIMIT $from, $max_results") or die(mysql_error());

$stuff = "Foods";
$G = $_SESSION['hG'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, food table Empty";
header("location:dataColl.php?poll=$msg");

}else{

include "dataColl.php";
 }
    
   } }
//-----------------------------------------------------------------------------------------------------------
if($_SESSION['hG']=="drinks"){
$getD = mysql_query("SELECT * FROM drinks");
for($i=0;$i<mysql_num_rows($getD);$i++){
$del_id = @$checkbox[$i];
$sql = "DELETE FROM drinks WHERE ID ='$del_id'";
$result = mysql_query($sql);
}

if($result){
 

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM drinks LIMIT $from, $max_results") or die(mysql_error());

$stuff = "Drinks";
$G = $_SESSION['hG'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, drinks table Empty";
header("location:dataColl.php?poll=$msg");

}else{

include "dataColl.php";
 }
    
   } }
if($_SESSION['hG']=="snacks"){
$getD = mysql_query("SELECT * FROM snacks");
for($i=0;$i<mysql_num_rows($getD);$i++){
$del_id = @$checkbox[$i];
$sql = "DELETE FROM snacks WHERE ID ='$del_id'";
$result = mysql_query($sql);
}

if($result){
 

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM snacks LIMIT $from, $max_results") or die(mysql_error());

$stuff = "Snacks";
$G = $_SESSION['hG'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, snacks table Empty";
header("location:dataColl.php?poll=$msg");

}else{

include "dataColl.php";
 }
    
   } }
if($_SESSION['hG']=="services"){
$getD = mysql_query("SELECT * FROM services");
for($i=0;$i<mysql_num_rows($getD);$i++){
$del_id = @$checkbox[$i];
$sql = "DELETE FROM services WHERE ID ='$del_id'";
$result = mysql_query($sql);
}

if($result){
 

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM services LIMIT $from, $max_results") or die(mysql_error());

$stuff = "Services";
$G = $_SESSION['hG'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, services table Empty";
header("location:dataColl.php?poll=$msg");

}else{

include "dataColl.php";
 }
    
   } }
  
}
}
 

if (isset($_GET['page']) and $_SESSION['G'] == "food"){
 $page = $_GET['page'];
 showFood();
//unset($_SESSION['G']);
     }
 
 function showFood(){

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

@$pageFor = "food";
$max_results = 4;

$from = (($page * $max_results) - $max_results);

$getData = mysql_query("SELECT * FROM food LIMIT $from, $max_results") or die("Failed to Query the Food table");
$_SESSION['hG'] = $Clicked = "food";
$stuff = "Foods";
$G = "Food";

$_SESSION['G'] = "food";

//echo "Value=". $_SESSION['G'];

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, Food table Empty";
header("location:dataColl.php?poll=$msg");
//header("location: dataColl.php?poll=$msg");
//include "dataColl.php";
}else{
//colorRow();
$msg =  "Some data found";
//header("location: dataColl.php?poll=$msg");
include "dataColl.php";

} 
   }
  
if (isset($_GET['page'])  and $_SESSION['G'] == "drinks"){
$page = $_GET['page'];
showDrinks();
 }

function showDrinks(){
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

@$pageFor = "drinks";
$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM drinks LIMIT $from, $max_results") or die("Failed to Query the Drinks table");

//$getData = mysql_query("SELECT * FROM drinks") or die("Failed to Query the Drinks table");
$_SESSION['hG'] = $Clicked="drinks";
$stuff = "Drinks";
$G = "Drink";
$_SESSION['G'] = "drinks";

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, Drinks table Empty";
header("location:dataColl.php?poll=$msg");
//header("location: dataColl.php?poll=$msg");
//include "dataColl.php";
}else{
$msg =  "Some data found";
//header("location: dataColl.php?poll=$msg");
include "dataColl.php";
}

}

if (isset($_GET['page'])  and $_SESSION['G'] == "snacks"){
$page = $_GET['page'];
showSnacks();
 }

function showSnacks(){
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

@$pageFor = "snacks";
$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM snacks LIMIT $from, $max_results") or die("Failed to Query the Snacks table");
//$getData = mysql_query("SELECT * FROM snacks") or die("Failed to Query the Snacks table");
$_SESSION['hG'] = $Clicked="snacks";
$stuff = "Snacks";
$G = "Snack";
$_SESSION['G'] = "snacks";

if(!mysql_num_rows($getData)>0){

$msg =  "No data found, Snacks table Empty";
header("location:dataColl.php?poll=$msg");
//header("location: dataColl.php?poll=$msg");
//include "dataColl.php";
}else{
$msg =  "Some data found";
//header("location: dataColl.php?poll=$msg");
include "dataColl.php";
}

}

if (isset($_GET['page'])  and $_SESSION['G'] == "services"){
$page = $_GET['page'];
showServices();
 }
 
function showServices(){

if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1; 

@$pageFor = "services";
$max_results = 4;

$from = (($page * $max_results) - $max_results);
$getData = mysql_query("SELECT * FROM services LIMIT $from, $max_results") or die("Failed to Query the Services table");

//$getData = mysql_query("SELECT * FROM services") or die("Failed to Query the Food table");
$_SESSION['hG'] = $Clicked="services";

$stuff = "Services";
$G = "Service";
$_SESSION['G'] = "services";

if(!mysql_num_rows($getData)>0){
$msg =  "No data found, Services table Empty";
header("location:dataColl.php?poll=$msg");
//header("location: dataColl.php?poll=$msg");
//include "dataColl.php";
}else{
$msg =  "Some data found";
//header("location: dataColl.php?poll=$msg");
include "dataColl.php";
}
}

$edit = @$_POST['edit'];
if(isset($edit)){

echo $hiddenField = $_POST['h'];

//$_SESSION['hF'] = $hiddenField;

//header("location:editStuff_con.php?poll=$hiddenField");
//echo "yes";

  
  
  }

?>